home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / cenviw1.zip / PICKFILE.LIB < prev    next >
Text File  |  1993-08-05  |  3KB  |  60 lines

  1. // PickFile.lib - Cmm code wrapper for a simple implementation of the
  2. //                GetOpenFileName() function found in the Windows
  3. //                Common Dialog DLL.  You may #include this file in
  4. //                your CMM source to have access to this version of
  5. //                GetOpenFileName().
  6.  
  7. // GetOpenFileName([MatchingFileSpec[,Title]])
  8.    // MatchingFileSpec: string file specification, including wildcard in the
  9.    //                   file name.  For example "C:\\WIN\\*.TXT" or
  10.    //                   "*.INI".  If this is not supplied or if it is
  11.    //                   NULL then *.* will be the default.
  12.    // Title: String to be the title of the open dialog box, if this is NULL
  13.    //        then Windows defaults to "Open".
  14.    // Return: Return a string that is the full file specification of the
  15.    //         file selected, or NULL if no file was selected.
  16. GetOpenFileName(MatchingFileSpec,Title)
  17. {
  18.    // The OpenFileName structure is very large, but most of its fields are
  19.    // are not used, so will set it all to zero except the few fields needed.
  20.    #define  OFN_MAX_FILESPECLEN  200
  21.    #define  OFN_SIZE             72
  22.    #define  OFN_FILENAME_OFFSET  24
  23.    #define  OFN_INIT_DIR_OFFSET  40
  24.    #define  OFN_TITLE_OFFSET     44
  25.    BLObSize(ofn,OFN_SIZE);
  26.    memset(ofn,0,OFN_SIZE);
  27.    BLObPut(ofn,0,OFN_SIZE,UWORD32);
  28.    BLObPut(ofn,4,ScreenHandle(),UWORD16);
  29.    BLObPut(ofn,6,Instance(),UWORD16);
  30.  
  31.    // if a title was supplied, then use it
  32.    if ( 1 < va_arg()  &&  NULL != Title ) {
  33.       BLObPut(ofn,OFN_TITLE_OFFSET,pointer(Title),UWORD32);
  34.    }
  35.  
  36.    // if filename was not supplied, then default to wildcard
  37.    if ( 0 < va_arg()  &&  NULL != MatchingFileSpec ) {
  38.       strcpy(ofn_spec,MatchingFileSpec);
  39.    } else {
  40.       strcpy(ofn_spec,"*.*");
  41.    }
  42.    ofn_parts = SplitFileName(ofn_spec);
  43.  
  44.    // store the dir part of the filename (without extra backslash)
  45.    ofn_dir = FullPath(ofn_parts.dir);
  46.    if ( ofn_dir[strlen(ofn_dir)-1] == '\\'  &&  strcmp(ofn_dir+1,":\\") )
  47.       ofn_dir[strlen(ofn_dir)-1] = 0;
  48.    BLObPut(ofn,OFN_INIT_DIR_OFFSET,pointer(ofn_dir),UWORD32);
  49.  
  50.    // set filename part of the filename, and also initialize it
  51.    memset(ofn_name,0,OFN_MAX_FILESPECLEN);
  52.    strcat(strcpy(ofn_name,ofn_parts.name),ofn_parts.ext);
  53.    BLObPut(ofn,OFN_FILENAME_OFFSET,pointer(ofn_name),UWORD32);
  54.    BLObPut(ofn,OFN_FILENAME_OFFSET+4,OFN_MAX_FILESPECLEN-1,UWORD32);
  55.  
  56.    return( DynamicLink("COMMDLG.DLL","GETOPENFILENAME",SWORD16,PASCAL,ofn)
  57.          ? ofn_name : NULL );
  58. }
  59.  
  60.